const commonUrl = 'https://hxt.daoyintc.com/hxt';//公共路径
const getUserToken = () => {
	return uni.getStorageSync("token");
}
function postRequest(url,data){
	var token = getUserToken()
    var promise = new Promise((resolve,reject)=>{
        var that = this;
        var params = data;
        uni.request({
            url:commonUrl+url,
            data:params,
            method:'POST',
            header:{
               'content-type':'application/x-www-form-urlencoded',
               'Authorization': token
            },
            success:function(res){
               resolve(res)
            },
            error:function(error){
               reject(error)
            }
        })
    })
    return promise
};

function postRequestJson(url,data){
	var token = getUserToken()
    var promise = new Promise((resolve,reject)=>{
        var that = this;
        var params = JSON.stringify(data);
        uni.request({
            url:commonUrl+url,
			dataType:'json',
            method:'POST',
			data:params,
            header:{
               'content-type':'application/json;charset=UTF-8',
               'Authorization': token
            },
            success:function(res){
               resolve(res)
            },
            error:function(error){
               reject(error)
            }
        })
    })
    return promise
};

//get 封装
function getRequest(url,data){
   var promise = new Promise((resolve,reject)=>{
       var that = this;
       var params = data;
       uni.request({
            url:commonUrl + url,
            data:params,
            method:'GET',
            success:function(res){
               resolve(res)
            },
            error:function(error){
               reject(error)
            }
       })
   })
   return promise
}

module.exports = {
   postRequest,
   getRequest,
   postRequestJson
}